package tsi

import (
	watchmessgae "earth/watch_tcp/watch_message"
	"errors"

	"github.com/sirupsen/logrus"
)

/*
设备上报 ICCID 协议
终端发送:
[DW*YYYYYYYYYYYYYYY*LEN*ICCID,iccid 号]
实例:[DW*334588000000156*001A*ICCID,89860000000000000007]
说明:设备开机后主动上报 1 次设备 iccid
平台回复:
[DW*YYYYYYYYYYYYYYY*LEN*ICCID]
实例:[DW*334588000000156*0005*ICCID]
*/

type ICCID struct {
	ICCID string // iccid 号
}

func DealICCID(watchMessage *watchmessgae.WatchMessage, deviceID string) error {
	// 校验消息长度
	if len(watchMessage.MessageContentList) < 1 {
		logrus.Error("message is too short:", watchMessage.MessageContentList)
		return errors.New("message is too short")
	}
	// 解析消息内容
	iccid := &ICCID{}
	iccid.ICCID = watchMessage.MessageContentList[0]
	return SendEvent(deviceID, iccid, "ICCID")
}
